package com.zry.fertilizer


import android.view.KeyEvent
import android.widget.Toast
import com.zry.fertilizer.databinding.ActivityMainBinding
import com.zry.fertilizer.presenter.MainPresenter
import com.zry.fertilizer.ui.base.BaseActivity
import com.zry.fertilizer.ui.fragment.HomeFragment
import com.zry.fertilizer.ui.fragment.MessageFragment
import com.zry.fertilizer.ui.fragment.UserFragment


class MainActivity : BaseActivity() {
    var homeFragment: HomeFragment? = null
    var messageFragment: MessageFragment? = null
    var userFragment: UserFragment? = null
    private var mainPresenter: MainPresenter? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_main
    }

    override fun initData() {
        val mainBinding: ActivityMainBinding = viewDataBinding as ActivityMainBinding
        mainPresenter = MainPresenter(this)
        mainBinding.handlerClick = mainPresenter

        mainPresenter?.selectStyle(R.id.mainLin01)
    }


    //退出时的时间
    private var mExitTime: Long = 0

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK && event?.repeatCount == 0) {
            exit()
            return true
        }
        return super.onKeyDown(keyCode, event)
    }

    private fun exit() {
        if (System.currentTimeMillis() - mExitTime > 2000) {
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show()
            mExitTime = System.currentTimeMillis()
        } else {
            myActivityManager?.AppExit()
        }
    }


}
